<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/tools.js"></script>
    <script src="../js/api_v1.js"></script>
</head>
<body>
    用户名：<input class="username" type="text"><br>
    密码：<input class="password" type="password"><br>
    <button>登录</button>
    <script>

        // 异步 用async 加 promise
        $("button").onclick = async function (){
            let username = $(".username").value ; 
            let password = $(".password").value ; 
            const res = await login({username,password});
            if( res['status'] == 1 ){
                alert("登录成功！");
            }
        }

        // 异步只使用promise需要then去接收promise对象的结果res
        // $("button").onclick = function (){
        //     let username = $(".username").value ; 
        //     let password = $(".password").value ; 
        //     const res = login({username,password});
        //     res.then(resolved=>{
        //         if( resolved.status == 1 ){
        //             alert("登录成功！");
        //         }
        //     });
        // }
    </script>
</body>
</html>